//
//  UIView+Frame.m
//  高仿暴走斗图
//
//  Created by huangsongyao on 16/3/7.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "UIView+Frame.h"

@implementation UIView (Frame)

#pragma mark -
#pragma mark - View_X

- (CGFloat)viewX {
    
    return CGRectGetMinX(self.frame);
}

- (void)setViewX:(CGFloat)xPoint {
    
    CGRect rect = self.frame;
    rect = CGRectMake(xPoint, CGRectGetMinY(rect), CGRectGetWidth(rect), CGRectGetHeight(rect));
    self.frame = rect;
}


#pragma mark -
#pragma mark - View_Y

- (CGFloat)viewY {
    
    return CGRectGetMinY(self.frame);
}

- (void)setViewY:(CGFloat)yPoint {
    
    CGRect rect = self.frame;
    rect = CGRectMake(CGRectGetMinX(rect), yPoint, CGRectGetWidth(rect), CGRectGetHeight(rect));
    self.frame = rect;
}


#pragma mark -
#pragma mark - View_Point

- (CGPoint)viewPoint {
    
    return CGPointMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame));
}

- (void)setViewPoint:(CGPoint)point {
    
    self.viewX = point.x;
    self.viewY = point.y;
}


#pragma mark -
#pragma mark - View_Width

- (CGFloat)viewWidth {
    
    return CGRectGetWidth(self.frame);
}

- (void)setViewWidth:(CGFloat)width {
    
    CGRect rect = self.frame;
    rect = CGRectMake(CGRectGetMinX(rect), CGRectGetMinY(rect), width, CGRectGetHeight(rect));
    self.frame = rect;
}


#pragma mark -
#pragma mark - View_Height

- (CGFloat)viewHeight {
    
    return CGRectGetHeight(self.frame);
}

- (void)setViewHeight:(CGFloat)height {
    
    CGRect rect = self.frame;
    rect = CGRectMake(CGRectGetMinX(rect), CGRectGetMinY(rect), CGRectGetWidth(rect), height);
    self.frame = rect;
}


#pragma mark -
#pragma mark - View_Size

- (CGSize)viewSize {
    
    return CGSizeMake(CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
}


- (void)setViewSize:(CGSize)size {
    
    self.viewWidth = size.width;
    self.viewHeight = size.height;
}


#pragma mark -
#pragma mark - View_Centry_X

- (CGFloat)viewCenterX {
    
    return self.center.x;
}

- (void)setViewCenterX:(CGFloat)centerX {
    
    self.center = CGPointMake(centerX, self.center.y);
}


#pragma mark -
#pragma mark - View_Centry_Y

- (CGFloat)viewCenterY {
    
    return self.center.y;
}

- (void)setViewCenterY:(CGFloat)centerY {
    
    self.center = CGPointMake(self.center.x, centerY);
}


#pragma mark -
#pragma mark - Get

- (CGFloat)viewMidX {
    
    return CGRectGetMidX(self.frame);
}

- (CGFloat)viewMidY {
    
    return CGRectGetMidY(self.frame);
}

- (CGFloat)viewMaxX {
    
    return CGRectGetMaxX(self.frame);
}

- (CGFloat)viewMaxY {
    
    return CGRectGetMaxY(self.frame);
}

- (CGFloat)viewMinX {
    
    return CGRectGetMinX(self.frame);
}

- (CGFloat)viewMinY {
    
    return CGRectGetMinY(self.frame);
}

//MPMoviePlayerViewController 缓冲进度
//NSArray *events = playerViewController.moviePlayer.accessLog.events;
//int count = events.count;
//for (int i = 0; i < count; i++)
//{
//    MPMovieAccessLogEvent *currentEvent = [events objectAtIndex:i];
//    double byts = currentEvent.indicatedBitrate;
//    int64_t byte = currentEvent.numberOfBytesTransferred;
//    int64_t bytes = currentEvent.numberOfBytesTransferred >> 10;
//    NSMutableString *strBytes = [[NSMutableString alloc] initWithCapacity:100];
//    [strBytes appendFormat:@"totalSize = %d byte", bytes];
//    if (bytes > 1024)
//    {
//        bytes = bytes >> 10;
//        [bytesS setString:@""];
//        [bytesS appendFormat:@"total = %d M", bytes];
//    }
//    NSLog(@"byte = %f M bytes = %lld", (float)byte / (1024 * 1024), bytes);
//}


@end
